package com.kun.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 文件下载
 * @author: KM
 * 2018年3月24日
 */
@Controller
public class UploadController {
	
	
	@RequestMapping(value="testDownload",method=RequestMethod.GET) 
	@ResponseBody
    public String testDownload(HttpServletResponse res) throws IOException{  
		String msg = "";
		try {
			res.setHeader("content-type", "application/octet-stream");  
	        res.setContentType("application/octet-stream");  
	        res.setHeader("Content-Disposition", "attachment;filename=CourseResource.jpg");  
	        File file=new File("F://ftp//upload.jpg");  
	        FileOutputStream fos=new FileOutputStream(file);  
	        res.setContentLengthLong(file.length());  
	        fos.close();  
	        msg = "success";
		} catch (Exception e) {
			msg = "failure";
			System.out.println(e.getMessage());
		}
        return msg;
    }

}
